#coding=utf-8
import yaml, requests,json,time,pymysql
from request_data import *

def write_yaml(path):
    with open(path,'w',encoding='utf-8')as file:
        yaml.dump(data,stream=file,allow_unicode=True)
        print('接口数据写入成功')
def read_yaml(num,name):
    with open('add_employee_requests.yaml','r',encoding='utf-8')as file1:
        data=yaml.load(file1,Loader=yaml.FullLoader)
        return data[num][name]

def send_requests(num,name,url,data,headers):
    if read_yaml(num,name)['method']=='post':
        re = requests.post(url, data=json.dumps(data), headers=headers)
        return  re
    if read_yaml(num,name)['method']=='get':
        re=requests.get(url, params=json.dumps(data),headers=headers)
        return  re
def mysql():
    #246数据库
    mysql_host = '172.16.70.246'
    mysql_port = 3306
    mysql_user = 'root'
    mysql_passwd = 'deke@2022'
    mysql_database = 'test246'
    conn= pymysql.connect(host=mysql_host,port=mysql_port, user=mysql_user, passwd=mysql_passwd, charset='utf8', db=mysql_database)
    return conn